package com.tledu.zyf.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.http.NameValuePair;
import com.tledu.zyf.util.HttpUtil;

@WebServlet("/getResult")
public class RecognitionServlet extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 设置字符编码
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");

		// 获取网络图片url
		String paramValue = request.getParameter("url");
		/**
		 * 请求的URL接口
		 */
		// String url =
		// "http://ai.shangyuninfo.com/api/flowers/identification/processImageByUrl/";

		String url = "http://59.111.104.104:8522/api/flowers/identification/processImageByUrl/";
		// String url = "http://www.baidu.com";
		/**
		 * 参数值
		 */
		Object[] params = new Object[] { "fileUrl" };
		/**
		 * 参数名
		 */
		Object[] values = new Object[] { paramValue };
		/**
		 * 获取参数对象
		 */
		List<NameValuePair> paramsList = HttpUtil.getParams(params, values);
		/**
		 * 发送get
		 */
		// Object result = HttpUtil.sendGet(url, paramsList);
		/**
		 * 发送post
		 */
		Object result2 = null;
		try {
			result2 = HttpUtil.sendPost(url, paramsList);
			response.getWriter().write(result2.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
